//获取应用实例
var app = getApp()
Page({
  data: {
    isShowall: true
  },
  onLoad: function (e) {
    var that = this;
    app.setNavColor(that);
    if (e && e.title) {
      that.setData({
        title: e.title
      })
      app.setNavtitle(e.title);
    } else {
      app.setNavtitle('商品分类');
    }
    if (!app.globalData.plumSession) {
      if (plumSession != '') {
        console.log('查询到登录信息');
        that.requestGoodFl();
        that.setData({
          isShowall: true,
          curGoodFl: null
        })
      } else {
        console.log('未查询到登录信息');
        app.wechatSq(that);
      }
    } else {
      // that.setBootomWrapH();
      that.requestGoodFl();
      that.setData({
        isShowall: true,
        curGoodFl: null
      })
    }
  },
  onShow: function () {
    var that = this;
    if (that.data.title) {
      app.setNavtitle(that.data.title);
    }
  },
  requestGoodFl: function () {
    console.log("请求接口");
    var that = this;
    var data = {};
    data.map = 'applet_goods_category_list';
    wx.showLoading({
      title: '加载中'
    })
    wx.request({
      url: app.globalData.requestUrl,
      data: data,
      success: function (res) {
        console.log(res.data.data);
        if (res.data.ec == 200) {
          that.setData({
            goodsFlList: res.data.data,
          })
        } else {
          console.log(res.data)
        }
      },
      complete: function () {
        wx.hideLoading();
        wx.stopPullDownRefresh();
      }
    });
  },
  searchPage: function () {
    wx.navigateTo({
      url: '../searchList/searchList'
    })
  },
  onPullDownRefresh: function () {
    var that = this;
    that.setData({
      isShowall: true,
      curGoodFl: null
    })
    that.requestGoodFl();
  },
  flGoods: function (e) {
    var oneid = e.currentTarget.dataset.oneid;
    var secondid = e.currentTarget.dataset.secondid;
    var title = e.currentTarget.dataset.title;
    console.log(oneid);
    console.log(secondid);
    wx.navigateTo({
      url: '/pages/allgoodsPage/allgoodsPage?oneid=' + oneid + '&secondid=' + secondid + '&title=' + title
    })
  },
  // 切换一级分类
  toggleGoodfl: function (e) {
    var that = this;
    var id = e.target.dataset.id;
    var onefl = e.target.dataset.onefl;
    that.setData({
      curGoodFl: id,
      curGooddata: onefl,
      isShowall: false,
      flintoView: 'leftfl' + id
    })
  },
  // 设置点餐区域高度
  setBootomWrapH: function () {
    var that = this;
    var query = wx.createSelectorQuery();
    wx.getSystemInfo({
      success: function (res) {
        query.select('#searchWrap').boundingClientRect(function (rect) {
          var bootomWrapH = res.windowHeight - rect.height;
          that.setData({
            topPartH: rect.height,
            bootomWrapH: bootomWrapH
          })
        }).exec()
      }
    })
  },
  makeCall: function () {
    app.makeCall();
  },
  onShareAppMessage: function (e) {
    wx.showShareMenu({
      withShareTicket: true
    })
    var that = this;

    console.log(title);
    var shareInfo = app.globalData.shareInfo;
    var title = shareInfo.shareTitle ? shareInfo.shareTitle : '商品分类';
    var cover = shareInfo.shareCover ? shareInfo.shareCover : '';
    app.getPoint(that);
    return {
      title: title,
      imageUrl: cover,
      path: '/pages/allFlGoodsPage/allFlGoodsPage'
    }
  },
  backsy: function () {
    app.backHome();
  },
})